package com.carl.zlds.tool.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.cglib.core.Converter;

public class ObjUtil {
    public ObjUtil() {
    }

    public static void copy(Object source, Object target) {
        BeanCopier copier = BeanCopier.create(source.getClass(), target.getClass(), false);
        copier.copy(source, target, (Converter)null);
    }

    public static <M, T> T processModel(M m, Class<T> clazz) {
        Object t = null;

        try {
            t = clazz.newInstance();
            copy(m, t);
        } catch (InstantiationException | IllegalAccessException var4) {
            var4.printStackTrace();
        }

        return (T) t;
    }

    public static <M, T> List<T> processModelList(List<M> list, Class<T> clazz) {
        List<T> resultList = new ArrayList();
        Iterator var3 = list.iterator();

        while(var3.hasNext()) {
            Object m = var3.next();

            try {
                T t = clazz.newInstance();
                copy(m, t);
                resultList.add(t);
            } catch (InstantiationException | IllegalAccessException var6) {
                var6.printStackTrace();
            }
        }

        return resultList;
    }
}
